'''
Created on 09-06-2012

@author: ahaw
'''
from PyQt4 import QtGui, QtCore
from Widgets import AudioPlayer
class SystemTrayIcon(QtGui.QSystemTrayIcon):
    def __init__(self, parent=None):
        '''
        Kontruktor iconki tray.
        Doawanie ikon
        laczenie zdarzen
        '''
        super(SystemTrayIcon, self).__init__()
        #self.icon.setIcon( QtGui.QIcon('directory') )
        self.setIcon(QtGui.QIcon.fromTheme("document-save"))

        self.right_menu = RightClick()
        self.setContextMenu(self.right_menu)
        self.activated.connect(self.click)
        
    def click(self, value):
        '''
        wznownienie/zatrzymanie odtwarzania po kliknieciu srodkowym przyickiem myszy
        '''
        if value ==self.MiddleClick:
            self.playPause()

    def trayNotice(self):
        '''
        komunikat po zminimalizowaniu do paskaZadan
        '''
        self.showMessage("PyMp", "PyMP is mimized to tray")
        
    def show(self):
        '''
        Wyswietlanie komunikatu po minimalizacji
        '''
        QtGui.QSystemTrayIcon.show(self)
        QtCore.QTimer.singleShot(1000, self.trayNotice)
    def playPause(self):
        '''
        zatrzymywanie/wznawianie odtwarzania
        '''
        AudioPlayer.playClicked(AudioPlayer.instance)

class RightClick(QtGui.QMenu):
    def __init__(self, parent=None):
        '''
        Menu kontekstowe trayicon
        '''
        QtGui.QMenu.__init__(self, "Menu", parent)
        icon = QtGui.QIcon('icons/oxygen/gtk-media-play.png')
        self.addAction(QtGui.QAction(icon,"&Play/Pause", self))
        self.triggered.connect(self.playPause)
    def playPause(self):
        '''
        zatrzymywanie/wznawianie odtwarzania
        '''
        AudioPlayer.playClicked(AudioPlayer.instance)
    